//
//  MM_AlertView.m
//  MallManage_IOS
//
//  Created by 张浩 on 2023/12/18.
//

#import "MM_AlertView.h"

@interface MM_AlertView ()

@property (nonatomic, copy) MM_AlertViewBlock alertBlock;

@end

@implementation MM_AlertView

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (self.alertBlock) {
        self.alertBlock(buttonIndex);
        self.alertBlock = nil;
    }
}

- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message withJH_AlertBlock:(MM_AlertViewBlock)alertBlock cancelButtonTitle:(NSString *)cancelButtonTitle ensureButtonTitle:(NSString *)ensureButtonTitle{
    
    self = [ super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:ensureButtonTitle, nil];
    if (self) {
        self.alertBlock = alertBlock;
    }
    return self;
}

+ (void)MM_AlertWithTitle:(NSString *)title message:(NSString *)message withJH_AlertBlock:(MM_AlertViewBlock)alertBlock cancelButtonTitle:(NSString *)cancelButtonTitle ensureButtonTitle:(NSString *)ensureButtonTitle {
    
    MM_AlertView * alert = [[MM_AlertView alloc]initWithTitle:title message:message withJH_AlertBlock:alertBlock cancelButtonTitle:cancelButtonTitle ensureButtonTitle:ensureButtonTitle];
    [alert show];
}


@end
